package controller;
import java.io.EOFException;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dao.LoginDAO;
import pojo.Login;
public class LoginController extends HttpServlet {
    protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
        response.setContentType("text/html;charset=UTF-8");
        request.setCharacterEncoding("UTF-8");
        HttpSession session=request.getSession();
        String username=request.getParameter("login-username");
        String password=request.getParameter("login-password");
        Login loginform=new Login(username,password);
        LoginDAO DAO=new LoginDAO();//跟数据库当中的信息进行匹配判断
        int check=DAO.checkLogin(loginform);
        System.out.println(username);
        System.out.println(password);

        if(check==2) {//管理员登录
            request.setAttribute("code",check);
            request.getRequestDispatcher("admin.jsp").forward(request,response);
        }
    }
}
